var orderNo = getValueByParam('orderNo'),
	addressInfo = {
		address: '广东省湛江市雷州市黄家村学府一号6栋2202',
		consignee: "李林",
		consigneePhone: '15168353219'
	};

$(() => {
	loadData();
	initListener();
})

initListener = () => {
	$("#copy_address").on('click', () => {
		copyToClipboard(JSON.stringify(addressInfo));
	});
	$("#copy_fwdh").on('click', () => {
		let text = $(`#bill_no`).val();
		copyToClipboard(text);
	});
	$("#edit_bill").on('click', () => {
		onModifyLogistics();
	});
	$("#view_logistics").on('click', () => {
		onViewLogistics();
	});
}

copyToClipboard = (text) => {
	var textarea = document.createElement('textarea');
	textarea.style.position = 'fixed';
	textarea.style.opacity = 0;
	textarea.value = text;
	document.body.appendChild(textarea);
	textarea.select();
	try {
		var successful = document.execCommand('copy');
		document.body.removeChild(textarea);
		var msg = successful ? '复制成功' : '失败';
		showToast(msg)
	} catch (err) {
		console.log('Oops, unable to copy');
		showToast('暂不支持复制功能')
	}
}

onModifyLogistics = () => {
	navigateTo(`edit_bill_no.html?orderNo=${orderNo}`)
}

onViewLogistics = () => {
	navigateTo(`delivery_detail.html?orderNo=${orderNo}`)
}

loadData = () => {
	let subLoading = layer.open({
		type: 2,
		shadeClose: false,
		content: '正在加载...'
	});
	setTimeout(() => {
		layer.close(subLoading);
		queryAfterServiceDetail(orderNo, res => {
			if (res.code == 200) {
				setValue(res.data);
			} else {
				setLoadState('stateUlr', loginFail());
			}
		})
	}, 500)
}

setValue = (data) => {
	let itemHtml = ``;
	$(`#list`).html('');
	let orderItemVOs = data.orderItemVOs;
	for (var j = 0; j < orderItemVOs.length; j++) {
		let childObj = orderItemVOs[j];

		itemHtml += `<div class="order_item_child">
						<img src="${childObj.goodsPictureUrl}" class="order_img" />
						<div class="order_content">
							<span class="title">${childObj.goodsName}</span>
							<span class="des">${childObj.specInfo[0].specValues},${childObj.specInfo[1].specValues}</span>
							<div class="list_item_child" style="justify-content: space-between;margin-top: 0.6rem;">
								<div class="goods_price">
									<span class="unit">¥</span>
									<span class="price">${childObj.actualPrice}</span>
								</div>
								<div class="goods_quantity">
									<span class="unit">X</span>
									<span class="num">${childObj.rightsQuantity}</span>
								</div>
							</div>
						</div>
					</div>`;
	}
	$(`#list`).html(itemHtml);
}
